$(document).ready(function() {
	var bannerTitleTop = null;
	var winHeight = $(window).height();
	bannerTitleTop = $('.benner-content').offset().top;

	if (bannerTitleTop < winHeight) {
		$('.benner-content').addClass('titlesTransformActive');
	}

	$('.tab-item').on('click', function(event) {
		var tabIndex = $(this).index();
		$(this).addClass('tab-active').siblings().removeClass('tab-active');
		$('.pop_img').eq(tabIndex).addClass('show_pop_img').siblings().removeClass('show_pop_img')
	})

	$(window).scroll(function() {
		f('miniprogram');
		f('chrome-tabs');
		f('content-title');
		f('platform-title');
		f('platform-desc');
		f('platform-tabs');
		f('platform-right');
		f('skinbox-content');
		f('safebox-title');
		f('safebox-tips');
	});


	var mySwiper = new Swiper('.swiper-container', {
		autoplay: {
			delay: 3000,
			disableOnInteraction: false, // 用户操作之后,不会停止自动轮播
		},
		loop: true, // 循环模式选项
		speed: 500, // 切换过程花费的时间
		slidesPerView: "auto", // 自适应显示 swiper-slide 的个数
		centeredSlides: true, // 默认第一块居中
		spaceBetween: 40, // swiper-slide 之间的间距
		slideToClickedSlide: true, // 点击切换
		pagination: {
			el: '.custom-pagination',
			clickable: true,
		},
	})


	function f(eleClassName) {
		var winHeight = $(window).height();
		var winScrollHeight = $(window).scrollTop();
		var ele2OffsetTop = $('.' + eleClassName).offset().top;
		var ele2height = $('.' + eleClassName).height();

		if (winScrollHeight < ele2OffsetTop + ele2height && winScrollHeight > ele2OffsetTop - winHeight + ele2height / 2) {
			if ($('.' + eleClassName).hasClass('titlesTransformActive') == false) {
				$("." + eleClassName).addClass("titlesTransformActive");
				
				if(eleClassName == 'safebox-tips'){
					numberInterval(1000, 2000, 50, 20, '.safeWebsiteNum span');
					numberInterval(50, 110, 2, 20, '.safeAttackNum span');
					numberInterval(1000, 2000, 50, 20, '.safeMumaNum span');
				}
				
			}
		}
	}
	
	
	// 数字动态增加
	function numberInterval(startNum, endNum, addNum, time, dom) {
		if (startNum < endNum) {
			startNum += addNum;
			if (startNum >= endNum * 0.6 && endNum * 0.8) {
				time = 60;
			} else if (startNum >= endNum * 0.8) {
				time = 80;
			};
			$(dom).html(startNum);
			setTimeout(function() {
				numberInterval(startNum, endNum, addNum, 20, dom);
			}, time)
		}
	};


})
